CXX = g++
CXXFLAGS = -std=c++17 -Wall -Wextra -I.

# 源文件
SRCS = Token.cpp Lexer.cpp AST.cpp Parser.cpp SymbolTable.cpp SemanticAnalyzer.cpp ExecutionPlan.cpp PredicatePushdownOptimizer.cpp test_parser.cpp interactive_compiler.cpp test_where.cpp
OBJS = $(SRCS:.cpp=.o)
TARGET = test_parser
TARGET_INTERACTIVE = interactive_compiler
TARGET_WHERE = test_where

# 默认目标
all: $(TARGET) $(TARGET_INTERACTIVE) $(TARGET_WHERE)

# 主测试程序
$(TARGET): Token.o Lexer.o AST.o Parser.o SymbolTable.o SemanticAnalyzer.o ExecutionPlan.o PredicatePushdownOptimizer.o test_parser.o
	$(CXX) $(CXXFLAGS) -o $@ $^

# 交互式编译器
$(TARGET_INTERACTIVE): Token.o Lexer.o AST.o Parser.o SymbolTable.o SemanticAnalyzer.o ExecutionPlan.o PredicatePushdownOptimizer.o interactive_compiler.o
	$(CXX) $(CXXFLAGS) -o $@ $^

# WHERE条件测试程序
$(TARGET_WHERE): Token.o Lexer.o AST.o Parser.o SymbolTable.o SemanticAnalyzer.o ExecutionPlan.o PredicatePushdownOptimizer.o test_where.o
	$(CXX) $(CXXFLAGS) -o $@ $^

# 编译规则
%.o: %.cpp
	$(CXX) $(CXXFLAGS) -c $< -o $@

# 清理
clean:
	rm -f $(OBJS) PredicatePushdownOptimizer.o $(TARGET) $(TARGET_INTERACTIVE) $(TARGET_WHERE)

# 运行测试
run: $(TARGET)
	./$(TARGET)

# 运行交互式编译器
interactive: $(TARGET_INTERACTIVE)
	./$(TARGET_INTERACTIVE)

# 运行WHERE条件测试
run_where_test: $(TARGET_WHERE)
	./$(TARGET_WHERE)

.PHONY: all clean run interactive run_where_test
